package greed;

/**
 * @author wcj
 * @Date 2021/7/6 22:35
 * @Version 1.0
 */
public class Stock {

    /**
     * 可以进行多次交易
     * ①贪心算法：只要今天买明天卖能赚钱，那么就买
     *
     * @param price
     * @return
     */
    public static int greed(int[] price) {
        int profit = 0;
        for (int i = 0; i < price.length - 1; i++) {
            if (price[i + 1] > price[i]) {
                profit += price[i + 1] - price[i];
            }
        }
        return profit;
    }
}
